package com.magina.antiPro.response;
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class RequestContextInterceptor implements HandlerInterceptor {
    DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    public RequestContextInterceptor() {
    }

    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) {
        String remote = httpServletRequest.getHeader("request_original_remoteAddr");
        if (remote == null) {
            remote = httpServletRequest.getHeader("X-Forwarded-For");
        }

        if (remote == null) {
            remote = httpServletRequest.getHeader("X-Real-IP");
        }

        if (remote == null) {
            remote = httpServletRequest.getRemoteAddr();
        }

        RequestContextProxy.put("request_url", httpServletRequest.getRequestURI());
        RequestContextProxy.put("request_time", LocalDateTime.now().format(this.dtf));
        RequestContextProxy.put("request_remote_address", remote);
        return true;
    }

    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
    }

    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
    }
}
